import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useEffect, useImperativeHandle, useRef, useState, } from "react";
// import { intl, nanoid10 } from "@/utils";
import { Button, CheckBox, Popup } from "devextreme-react";
// import { useModel } from "umi";
import "./_style.less";
import { LayoutD } from "~/public/cpas-ui/components-bs/Layout";
import { DevGrid } from "~/public/cpas-ui";
import { columnsDataTop, columnsDataBottom } from "./columnData";
import { getPZBOneVoucherDetail, getPZBOneVoucherDetailOfAssist, } from "./DraftApi";
const AccountingVoucherPupop = React.forwardRef((props, ref) => {
    const [visiblePopup, setVisiblePopup] = useState(false);
    const rowDataRef = useRef({});
    const [rowDataObj, setRowDataObj] = useState(null);
    const devGridRef = useRef(null);
    const [oneVoucherDetail, setOneVoucherDetail] = useState([]);
    const [oneVoucherDetailAssist, setOneVoucherDetailAssist] = useState([]);
    const [oneVoucherDetail0, setOneVoucherDetail0] = useState({});
    const [btnArr, setBtnArr] = useState([]);
    const [btnArrIndex, setBtnArrIndex] = useState(0);
    const [checkBoxFzz, setCheckBoxFzz] = useState(true);
    const [checkBoxFzzAll, setCheckBoxFzzAll] = useState(true);
    const onCancel = () => {
        setVisiblePopup(false);
        setOneVoucherDetailAssist([]);
        setOneVoucherDetail([]);
        setOneVoucherDetail0({});
        setBtnArrIndex(0);
        setBtnArr([]);
    };
    const getPZBOneVoucherDetaiList = async (tempRowData) => {
        const res = await getPZBOneVoucherDetail({
            dbname: tempRowData.dbname,
            Data_ID: tempRowData.Data_ID,
            PZRQ: tempRowData.PZRQ,
            PZLX: tempRowData.PZLX,
            PZBH: tempRowData.PZBH,
        });
        if (res.success) {
            setOneVoucherDetail(res.data);
            setOneVoucherDetail0(res.data[0]);
        }
        else {
            setOneVoucherDetail([]);
            setOneVoucherDetail0({});
        }
    };
    const getPZBOneVoucherDetailOfAssistList = async (tempRowData) => {
        const res = await getPZBOneVoucherDetailOfAssist({
            dbname: tempRowData.dbname,
            Data_ID: tempRowData.Data_ID,
            PZRQ: tempRowData.PZRQ,
            PZLX: tempRowData.PZLX,
            PZBH: tempRowData.PZBH,
            FLID: tempRowData?.FLID ?? "",
        });
        if (res.success) {
            setOneVoucherDetailAssist(res.data);
        }
        else {
            setOneVoucherDetailAssist([]);
        }
    };
    // 自定义方法
    useImperativeHandle(ref, () => ({
        showPupop: (rowData, gapArr) => {
            setVisiblePopup(true);
            console.log(rowData, gapArr, "@@@");
            setBtnArrIndex(0);
            setCheckBoxFzz(true);
            setCheckBoxFzzAll(true);
            rowDataRef.current = rowData;
            setRowDataObj(rowData);
            setBtnArr(gapArr);
        },
    }));
    useEffect(() => {
        if (rowDataObj?.PZBH) {
            getPZBOneVoucherDetaiList(rowDataObj);
            getPZBOneVoucherDetailOfAssistList(rowDataObj);
        }
    }, [rowDataObj]);
    function topContainer() {
        return (_jsx(DevGrid.RangeTap, { className: ` PaperDevSortableGrid devHeadersCenter `, height: "100%", width: "100%", ref: devGridRef, dataSource: oneVoucherDetail, keyExpr: "FLID", defaultColumns: columnsDataTop, showBorders: true, showRowLines: true, showColumnLines: true, allowColumnResizing: true, onCellClick: (e) => {
                const { rowType, data } = e;
                if (rowType === "data") {
                    if (!checkBoxFzzAll) {
                        getPZBOneVoucherDetailOfAssistList({
                            ...rowDataObj,
                            FLID: data.FLID,
                        });
                    }
                }
            }, searchPanel: {
                visible: false,
                width: 180,
                placeholder: "",
            }, paging: {
                enabled: false,
            }, loadPanel: { enabled: true }, scrolling: {
                mode: "virtual",
                rowRenderingMode: "virtual",
                renderAsync: true,
            }, columnMinWidth: 50, sheetName: `记账凭证-账单`, excelName: `记账凭证` }));
    }
    function bottomContainer() {
        return (_jsxs("div", { style: { height: "calc(100% - 35px)", marginBottom: "10px" }, className: "bottomContainBox", children: [(checkBoxFzz || checkBoxFzzAll) && (_jsx(DevGrid.RangeTap, { className: ` PaperDevSortableGrid devHeadersCenter `, height: "100%", width: "100%", ref: devGridRef, dataSource: oneVoucherDetailAssist, keyExpr: "FLID", defaultColumns: columnsDataBottom, showBorders: true, showRowLines: true, showColumnLines: true, allowColumnResizing: true, searchPanel: {
                        visible: false,
                        width: 180,
                        placeholder: "",
                    }, paging: {
                        enabled: false,
                    }, loadPanel: { enabled: true }, scrolling: {
                        mode: "virtual",
                        rowRenderingMode: "virtual",
                        renderAsync: true,
                    }, columnMinWidth: 50, sheetName: `记账凭证-辅助账`, excelName: `记账凭证` })), _jsx("div", { className: "titleBox", children: _jsxs("div", { className: "leftTitle", children: [_jsxs("div", { className: "leftTitleBox", children: [_jsx("div", { className: "leftTitleBoxText", children: "\u7F16\u5236\u4EBA\uFF1A" }), _jsx("div", { className: "leftTitleBoxBorder textColor", children: oneVoucherDetail0?.TZR ?? "" })] }), _jsxs("div", { className: "leftTitleBox", children: [_jsx("div", { className: "leftTitleBoxText", children: "\u5BA1\u6838\u4EBA\uFF1A" }), _jsx("div", { className: "leftTitleBoxBorder textColor", children: oneVoucherDetail0?.SHR ?? "" })] }), _jsxs("div", { className: "leftTitleBox", children: [_jsx("div", { className: "leftTitleBoxText", children: "\u8BB0\u8D26\u4EBA\uFF1A" }), _jsx("div", { className: "leftTitleBoxBorder textColor", children: oneVoucherDetail0?.JZR ?? "" })] }), _jsxs("div", { className: "leftTitleBox", children: [_jsx("div", { className: "leftTitleBoxText", children: "\u9644\u4EF6\u5F20\u6570\uFF1A" }), _jsx("div", { className: "leftTitleBoxBorder textColor", children: oneVoucherDetail0?.PZZS ?? 0 })] })] }) })] }));
    }
    return (_jsx(Popup, { visible: visiblePopup, title: "\u8BB0\u8D26\u51ED\u8BC1", width: "80vw", height: "70vh", onHiding: () => {
            onCancel();
        }, children: _jsxs("div", { style: { height: "100%", width: "100%" }, children: [_jsxs("div", { style: {
                        height: "calc(100% - 40px)",
                        width: "100%",
                        overflow: "hidden",
                        border: "1px solid #000",
                    }, children: [_jsxs("div", { className: "jzpzTitleBox", children: [_jsx("div", { className: "headerTitleCenter", children: _jsxs("div", { className: "headerTitleCenterText textColor", children: ["\u8BB0\u8D26\u51ED\u8BC1", _jsx("div", { className: "headerTitleCenterborder" })] }) }), _jsxs("div", { className: "titleBox", children: [_jsxs("div", { className: "leftTitle", children: [_jsxs("div", { className: "leftTitleBox", children: [_jsx("div", { className: "leftTitleBoxText", children: "\u51ED\u8BC1\u65E5\u671F\uFF1A" }), _jsx("div", { className: "leftTitleBoxBorder textColor", children: rowDataObj?.PZRQ ?? "" })] }), _jsxs("div", { className: "leftTitleBox", children: [_jsx("div", { className: "leftTitleBoxText", children: "\u51ED\u8BC1\u7C7B\u578B\uFF1A" }), _jsx("div", { className: "leftTitleBoxBorder textColor", children: rowDataObj?.PZLX ?? "" })] }), _jsxs("div", { className: "leftTitleBox", children: [_jsx("div", { className: "leftTitleBoxText", children: "\u51ED\u8BC1\u7F16\u53F7\uFF1A" }), _jsx("div", { className: "leftTitleBoxBorder textColor", children: rowDataObj?.PZBH ?? "" })] })] }), _jsxs("div", { className: "rightBoxBtn", children: [_jsx(Button, { width: 80, text: "\u4E0A\u4E00\u5F20", type: "default", stylingMode: "text", disabled: btnArrIndex === 0, onClick: () => {
                                                        setBtnArrIndex((oldItem) => {
                                                            let newData = oldItem;
                                                            newData = newData - 1;
                                                            setRowDataObj(btnArr[newData]);
                                                            return newData;
                                                        });
                                                    } }), _jsx(Button, { width: 80, text: "\u4E0B\u4E00\u5F20", type: "default", stylingMode: "text", disabled: btnArrIndex === btnArr.length - 1, onClick: () => {
                                                        setBtnArrIndex((oldItem) => {
                                                            let newData = oldItem;
                                                            newData = newData + 1;
                                                            setRowDataObj(btnArr[newData]);
                                                            return newData;
                                                        });
                                                    } })] })] })] }), _jsx("div", { style: { width: "100%", height: "calc(100% - 80px)" }, children: _jsx(LayoutD
                            // columnSize="100%"
                            , { 
                                // columnSize="100%"
                                columnSize: "70%", topSlot: topContainer(), bottomSlot: bottomContainer() }) })] }), _jsxs("div", { style: {
                        display: "flex",
                        alignItems: "center",
                        justifyContent: "left",
                        marginTop: "8px",
                    }, children: [_jsx(CheckBox, { text: "\u663E\u793A\u8F85\u52A9\u8D26\u4FE1\u606F", value: checkBoxFzz, onValueChanged: (e) => {
                                console.log(e.value, "@@@ e.value");
                                setCheckBoxFzz(e.value);
                            }, style: { marginRight: "15px" } }), _jsx(CheckBox, { text: "\u663E\u793A\u5168\u90E8\u8F85\u52A9\u8D26\u4FE1\u606F", value: checkBoxFzzAll, onValueChanged: (e) => {
                                console.log(e.value, "@@@ e.value");
                                setCheckBoxFzzAll(e.value);
                                if (e.value) {
                                    getPZBOneVoucherDetailOfAssistList(rowDataObj);
                                }
                            } })] })] }) }));
});
export default AccountingVoucherPupop;
